package com.china_goldcard.igas.http.base;

import com.china_goldcard.igas.core.AppContext;
import com.china_goldcard.igas.enums.ClientType;
import com.china_goldcard.igas.enums.ProjectType;
import com.china_goldcard.igas.utils.DateUtils;
import com.china_goldcard.igas.utils.TokenUtils;
import com.china_goldcard.igas.utils.VersionUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Headers;


/**
 * Created by jk on 16/10/10.
 */

public class APIHeader {

    private static APIHeader instance;

    /**
     * 私有的构造函数
     */
    private APIHeader(){

    }

    /**
     * 获取单利的方法
     * @return
     */
    public static APIHeader getInstance(){
        if (instance == null){
            instance = new APIHeader();
        }
        return instance;
    }

    private String name = "admin";

    private String pwd = "admin";

    private String UserAgent = "IResource";

    private String version = VersionUtils.getAppVersionCode(AppContext.getInstance()) + "";

    private String userId = "";

    private String clientType = ClientType.ANDROID.getValue();

    private String projectType = ProjectType.STANDARD.getValue();

    public Headers headers(){
        Map<String,String> map = new HashMap<>();
        String timeStap = DateUtils.dateToStr(new Date(),"yyyyMMddHHmmss");
        map.put("name",name);
        map.put("pwd",pwd);
        map.put("timeStap",timeStap);
        map.put("sign",TokenUtils.token(name,pwd,timeStap));
        map.put("User-Agent",UserAgent);
        map.put("version",version);
        map.put("userId",userId);
        map.put("clientType",clientType);
        map.put("projectType",projectType);
        return Headers.of(map);
    }

}
